__app.define('products_VM_Extend.js', function () {
  var productDetail_VM_Extend = {
    agentVueMounted: function (opt) {
      opt.vm.formatProductList = (res) => {
        //调用你的接口，把res这些处理逻辑都包进去
        // res.data[0].fSalePrice = 123
        getTop3HotProducts()
        editPrice(res.data);
        res.data.forEach(v => {
          // debugger
          opt.vm.$util.addUnitEnable(v, v);
          // 只用于展示，和输入框的内容区分开
          if (v.__onlyAuxEnable && v.oProductAuxUnit && v.oProductAuxUnit.oUnit) {
            v.buyQuantity = v.iMinOrderQuantity = v.iMinOrderQuantity / v.oProductAuxUnit.iConversionRate; // 辅计量
            v.__showUnit = v.oProductAuxUnit.oUnit;
          } else {
            v.buyQuantity = v.iMinOrderQuantity; // 主计量
            v.__showUnit = v.oUnit;
          }
          v.productImg = v.imgUrl;
        });
        opt.vm.productList = opt.vm.pageSize > 10 ? res.data : res.data.splice(0, opt.vm.pageSize);
        // 首页缓存数据传递过来的标识符
        opt.vm.serviceTab = res.serviceTab;
        opt.vm.isEnd = res.isEnd;
        opt.vm.totalCount = res.totalCount;

        if (!res.data || res.data.length === 0) {
          opt.vm.isNoDate = true;
        }
        // getTop3HotProducts(Math.ceil(opt.vm.productList.length / 4)).then((res) => {
        //   console.log("res",res)
        //   res.forEach((v, index) => {
        //     v.sortTitle = `HOT ${index + 1}`;
        //   });
        //   opt.vm.hotProducts = res;
        // });
      }
      var getTop3HotProducts = function() {
        return new Promise((resolve, reject)=> {
          __app.ajax({
            isLocal: true,
            type: "GET",
            url: "archives/product/getTop3HotProducts?isArchive=1&pageSize=5",
            dataType: "json",
            success: function(args) {
              editPrice(args)
              opt.vm.hotProducts = args;
            }
          })
        })
      }
      function editPrice(data) { 
        let obj = {
          customer: window.__app.mainV.$store.getters.currentUser.agentId,
          deliveryMethod: '自提',
          receiveAddress: '',
          productDetail: [],
        }
        data.forEach(element => {
          let product = {
            productCode: element.cCode,
            productId: element.id,
            org: element.saleOrgId,
            priceQty: 1,
            productUnitId: element.mainUnit.id,
            currency: '1655486829428736015',
            stockId: ''
          }
          obj.productDetail.push(product)
        });
        const url = 'https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3'
        __app.ajax({
          type: "POST",
          data: obj,
          url: url,
          success: (res) => {
            data.forEach((item) => {
              item.fSalePrice = res[item.id].price
            })
            // debugger
          },
          error: function (error) {
            debugger
          }
        })
      }
    },
  };
  return productDetail_VM_Extend;
});